import Vue from 'vue'
import VueRouter from 'vue-router'
// import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/Login'
  },
  {
    path: '/Login',
    name: 'Login',
    component: () => import(/* webpackChunkName: "about" */ '../views/login/Login.vue') //第一版登录页
  },
  {
    path: '/YgHome',
    name: 'YgHome',
    component: () => import(/* webpackChunkName: "about" */ '../views/home/YgHome.vue'),
    redirect: '/Home',
    children: [
      {
        path: '/Home',
        meta: {
          title: '首页'
        },
        component: () => import('../views/menu/Home.vue'), // 跳转首页
      },
      {
        path: '/ParamUser',
        meta: {
          title: '用户配置'
        },
        component: () => import('../views/menu/ParamUser.vue') // 跳转用户配置
      },
      {
        path: '/ParamTopic',
        meta: {
          title: '订阅配置'
        },
        component: () => import('../views/menu/ParamTopic.vue') // 跳转topic配置
      },
      {
        path: '/ParamGateway',
        meta: {
          title: '网关配置'
        },
        component: () => import('../views/menu/ParamGateway.vue') // 跳转网关配置
      },
      {
        path: '/ParamTerminal',
        meta: {
          title: '终端配置'
        },
        component: () => import('../views/menu/ParamTerminal.vue') // 跳转终端配置
      },
      {
        path: '/ParamYX',
        meta: {
          title: '遥信配置'
        },
        component: () => import('../views/menu/ParamYX.vue') // 跳转遥信配置
      },
      {
        path: '/ParamYC',
        meta: {
          title: '遥测配置'
        },
        component: () => import('../views/menu/ParamYC.vue') // 跳转遥测配置
      },
      {
        path: '/ParamYM',
        meta: {
          title: '遥脉配置'
        },
        component: () => import('../views/menu/ParamYM.vue') // 跳转遥脉配置
      },
      {
        path: '/ParamYK',
        meta: {
          title: '遥控配置'
        },
        component: () => import('../views/menu/ParamYK.vue') // 跳转遥控配置
      }, {
        path: '/ParamYT',
        meta: {
          title: '遥调配置'
        },
        component: () => import('../views/menu/ParamYT.vue') // 跳转遥调配置
      },
      {
        path: '/ParamStatic',
        meta: {
          title: '静态参数'
        },
        component: () => import('../views/menu/ParamStatic.vue') // 跳转静态参数
      },
      {
        path: '/ParamTimedTask',
        meta: {
          title: '定时任务'
        },
        component: () => import('../views/menu/ParamTimedTask.vue') // 跳转定时任务
      },
      {
        path: '/ParamGraphic',
        meta: {
          title: '一次图配置'
        },
        component: () => import('../views/menu/ParamGraphic.vue') // 跳转一次图配置
      },
      {
        path: '/ParamReport',
        meta: {
          title: '历史报表'
        },
        component: () => import('../views/menu/ParamReport.vue') // 跳转报表配置
      },
      {
        path: '/ParamTimeReport',
        meta: {
          title: '实时报表'
        },
        component: () => import('../views/menu/ParamTimeReport.vue') // 跳转报表配置
      },
      {
        path: '/AlarmEvent',
        meta: {
          title: '事件和告警'
        },
        component: () => import('../views/menu/AlarmEvent.vue') // 跳转系统配置
      },
      {
        path: '/DataQuery',
        meta: {
          title: '数据查询'
        },
        component: () => import('../views/menu/DataQuery.vue') // 跳转系统配置
      },
      {
        path: '/ParamClientId',
        meta: {
          title: '当前客户端'
        },
        component: () => import('../views/menu/ParamClientId.vue') // 跳当前客户端
      },
      {
        path: '/ParamSystem',
        meta: {
          title: '系统配置'
        },
        component: () => import('../views/menu/ParamSystem.vue') // 跳转系统配置
      },
      {
        path: '/ParamConfig',
        meta: {
          title: '监控大屏'
        },
        component: () => import('../views/menu/ParamConfig.vue') // 跳转监控配置
        // component: () => import('../components/ParamConfig/indexcopy.vue') // 跳转监控配置
      },
      {
        path: '/LicenseCode',
        meta: {
          title: '授权码管理'
        },
        component: () => import('../views/menu/LicenseCode.vue'), // 跳转授权码管理
      },
      {
        path: '/ParamVideo',
        meta: {
          title: '监控配置'
        },
        component: () => import('../views/menu/ParamVideo.vue'), // 跳转监控管理配置
      },
      {
        path: '/CheShi',
        meta: {
          title: '测试页面'
        },
        component: () => import('../views/menu/CheShi.vue'), // 跳转监控管理配置
      },
    ],
  },
  {
    path: '/TopologyIndex',
    name: 'TopologyIndex',
    component: () => import('../views/topology/TopologyIndex.vue'), // 跳转组态构建
    meta: {
      keepAlive: false, // 不需要缓存当前页面
      rank: 1,
      attribution: 'Teacher_classification' // 归属父级页面
    }
  },
  {
    path: '/Preview',
    component: () => import('../views/topology/Preview.vue') // 跳转预览组态
  },
  {
    path: '/bigscreenDesigner',
    name: 'bigscreenDesigner',
    meta: {
      title: '大屏配置'
    },
    component: () => import('../views/bigscreenDesigner/designer/index.vue') // 跳转大屏页面配置
  },
  {
    path: '/bigscreenViewer',
    meta: {
      title: '大屏预览'
    },
    component: () => import('../views/bigscreenDesigner/viewer/index.vue') // 跳转大屏页面配置
  },
  {
    path: '/viewer',
    meta: {
      title: '监视大屏'
    },
    component: () => import('../views/menu/Viewer.vue'), // 跳转监视大屏配置
  },
  {
    path: '/Dashboard',
    name: 'Dashboard',
    meta: {
      title: '监视大屏'
    },
    component: () => import('../views/menu/Dashboard.vue'), // 跳转监视大屏一配置
  },
  {
    path: '/LogView',
    meta: {
      title: '日志监视'
    },
    component: () => import('../views/menu/LogView.vue'), // 跳转监视大屏一配置
  },

]

const router = new VueRouter({
  mode: 'history',
  // mode: 'hash',
  // base: process.env.BASE_URL,
  routes
})

// 挂在路由导航守卫
// router.beforeEach((to, from, next) => {
//   // console.log(to, from, next)
//   // to 将要访问路径
//   // from 代表从哪个函数跳转而来
//   // next 是一个函数，代表放行
//   //        next()  放行   next('路径') 强制跳转
//   // if (to.path === '/Login') return next()
//   // // 获取token  访问其他路径必须携带token
//   // const tokenStr = localStorage.getItem('token')
//   // if (!tokenStr) return next('/Login')
//   // next()
// })

router.afterEach((to, from) => {
  if (to.meta.title) {
    document.title = to.meta.title //修改网页的title
  } else {
    document.title = '本地监控系统'
  }
})
// 重复点击导航时，控制台出现报错 ，虽然不影响功能使用，但也不能坐视不管。
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

export default router
